//
//  CZDismissAnimation.swift
//  GZWeibo666
//
//  Created by iOS on 16/05/9.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

/// 关闭时的转场动画
class CZDismissAnimation: NSObject, UIViewControllerAnimatedTransitioning {

    // 返回dismiss转场动画需要的时间
    func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
        return 0.25
    }
    
    // 在这个方法里面执行dismiss转场动画
    func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
        // 获取modal出来的控制器的view
        let fromView = transitionContext.viewForKey(UITransitionContextFromViewKey)
        
        // 动画
        UIView.animateWithDuration(transitionDuration(transitionContext), animations: { () -> Void in
            fromView?.transform = CGAffineTransformMakeScale(1, 0.01)
            }) { (_) -> Void in
                // 调用转场动画完成
                transitionContext.completeTransition(true)
        }
    }
}
